//package com.inspur.edp.cef.generator.coreGenerator.base.serializer;
//
//import com.inspur.edp.caf.generator.baseInfo.TypeInfo;
//import com.inspur.edp.caf.generator.method.ClassMethodGenerator;
//import com.inspur.edp.caf.generator.utils.ExpressionUtils;
//import com.inspur.edp.cef.designtime.api.IGspCommonField;
//import com.inspur.edp.cef.designtime.api.element.GspElementObjectType;
//import com.inspur.edp.cef.entity.entity.ICefData;
//import com.inspur.edp.cef.generator.coreGenerator.base.entityGenerator.CefDataTypeImplGeneratorContext;
//import com.inspur.edp.cef.generator.coreGenerator.entityGenerator.serializer.CMChangeJsonConvertorGenUtils;
//import com.inspur.edp.cef.generator.overall.GenUtils;
//import com.inspur.edp.das.commonmodel.IGspCommonElement;
//import com.inspur.edp.udt.designtime.api.entity.SimpleDataTypeDef;
//import com.inspur.edp.udt.designtime.api.entity.UnifiedDataTypeDef;
//import java.util.ArrayList;
//import org.eclipse.jdt.core.dom.AST;
//import org.eclipse.jdt.core.dom.Block;
//import org.eclipse.jdt.core.dom.CastExpression;
//import org.eclipse.jdt.core.dom.Expression;
//import org.eclipse.jdt.core.dom.MethodInvocation;
//import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword;
//import org.eclipse.jdt.core.dom.Statement;
//import org.eclipse.jdt.core.dom.StringLiteral;
//import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
//import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
//
//// public abstract void  writeEntityBasicInfo(JsonWriter writer, IValueObjData data, JsonSerializer
//// serializer);
//public abstract class WriteEntityBasicInfoGenerator extends ClassMethodGenerator {
//
//  protected CefDataTypeImplGeneratorContext dataTypeGenContext;
//
//  protected WriteEntityBasicInfoGenerator(CefDataTypeImplGeneratorContext dataTypeGenContext) {
//    this.dataTypeGenContext = dataTypeGenContext;
//  }
//
//  protected static final String methodName = "writeEntityBasicInfo";
//  protected static final String paramWriter = "writer";
//  protected static final String paramData = "data";
//  protected static final String paramserializer = "serializer";
//  protected static final String param_EntityAs = "entityData";
//
//  @Override
//  protected Block buildMethodBody() {
//    Block result = getTypeAsBlock();
//    for (IGspCommonField item : dataTypeGenContext.dataType.getContainElements()) {
//      ArrayList<Statement> tempRef_result = new ArrayList<Statement>();
//      writeElementGen(item, tempRef_result);
//      result.statements().addAll(tempRef_result);
//    }
//    return result;
//  }
//
//  private Block getTypeAsBlock() {
//    Block block = ast.newBlock();
//    TypeInfo dataType =
//        new TypeInfo(dataTypeGenContext.dataType.getGeneratedEntityClassInfo().getClassName());
//    dataType.setTypePackageName(
//        dataTypeGenContext.dataType.getGeneratedEntityClassInfo().getClassNamespace());
//    VariableDeclarationFragment variableDeclarationFragment = ast.newVariableDeclarationFragment();
//    variableDeclarationFragment.setName(ast.newSimpleName(param_EntityAs));
//    CastExpression castExpression = ast.newCastExpression();
//    castExpression.setType(ast.newSimpleType(ast.newName(dataType.getTypeFullName())));
//    castExpression.setExpression(ast.newSimpleName(paramData));
//    variableDeclarationFragment.setInitializer(castExpression);
//    VariableDeclarationStatement variableDeclarationStatement = ast
//        .newVariableDeclarationStatement(variableDeclarationFragment);
//    variableDeclarationStatement
//        .setType(ast.newSimpleType(ast.newName(dataType.getTypeFullName())));
//    block.statements().add(variableDeclarationStatement);
//    return block;
//  }
//
//  private void writeElementGen(IGspCommonField element, ArrayList<Statement> result) {
//
//    MethodInvocation valueExpression = ast.newMethodInvocation();
//    valueExpression.setExpression(ast.newSimpleName(param_EntityAs));
//    valueExpression.setName(ast.newSimpleName("get" + element.getLabelID()));
//    writeElementGen(ast, element, result, dataTypeGenContext, valueExpression);
//    addImport(ICefData.class.getTypeName());
//  }
//
//  public static void writeElementGen(
//      AST ast,
//      IGspCommonField element,
//      ArrayList<Statement> result,
//      CefDataTypeImplGeneratorContext dataTypeGenContext,
//      Expression propValueArgument) {
//    if (element.getIsUdt()) {
//      writeUdtElementGen(ast, element, result, dataTypeGenContext, propValueArgument);
//      return;
//    }
//    if (element.getObjectType() == GspElementObjectType.DynamicProp) {
//      writeDynmiacPropElementGen(ast, element, result, propValueArgument);
//      return;
//    }
//    switch (element.getObjectType()) {
//      case None:
//        writeBasicElementGen(ast, element, result, dataTypeGenContext, propValueArgument);
//        break;
//      case Association:
//        writeAssElementGen(ast, element, result, dataTypeGenContext, propValueArgument);
//        break;
//      case Enum:
//        writeEnumElementGen(ast, element, result, propValueArgument);
//        break;
//      default:
//        throw new RuntimeException();
//    }
//  }
//
//  //	protected final void writeDynamicPropSetValue(JsonGenerator writer, SerializerProvider
//  //        serializerProvider,IDynamicPropSet data, String propertyName, IDynamicPropSerItem serItem)
//  private static void writeDynmiacPropElementGen(
//      AST ast, IGspCommonField element, ArrayList<Statement> result, Expression propValueArgument) {
//    MethodInvocation methodInvocation = ast.newMethodInvocation();
//    methodInvocation
//        .setName(ast.newSimpleName(CMChangeJsonConvertorGenUtils.mName_WriteDynamicPropSetValue));
//    methodInvocation.arguments().add(ast.newSimpleName(paramWriter));
//    methodInvocation.arguments().add(ast.newSimpleName(paramserializer));
//    methodInvocation.arguments().add(propValueArgument);
//    methodInvocation.arguments().add(ExpressionUtils.getStringLiteral(ast, element.getLabelID()));
//    methodInvocation.arguments()
//        .add(ast.newSimpleName(DynamicSerItemsFieldGenerator.getFieldName(element)));
//    result.add(ast.newExpressionStatement(methodInvocation));
//  }
//
//  private static void writeUdtElementGen(
//      AST ast,
//      IGspCommonField element,
//      ArrayList<Statement> result,
//      CefDataTypeImplGeneratorContext dataTypeGenContext,
//      Expression propValueExpression) {
//
//    UnifiedDataTypeDef udtDef =
//        dataTypeGenContext
//            .coreGenContext
//            .getCefGenContext()
//            .getMetadataContent(element.getUdtPkgName(), element.getUdtID());
//    MethodInvocation methodInvocation = ast.newMethodInvocation();
//    methodInvocation.setName(
//        ast.newSimpleName(CMChangeJsonConvertorGenUtils.mName_WriteNestedValue));
//    methodInvocation.arguments().add(ast.newSimpleName(paramWriter));
//    methodInvocation.arguments().add(ast.newSimpleName(paramserializer));
//    StringLiteral udtConfigId = ast.newStringLiteral();
//    udtConfigId.setLiteralValue(udtDef.getUdtType());
//    methodInvocation.arguments().add(udtConfigId);
//    CastExpression castCefDataExpr = ast.newCastExpression();
//    castCefDataExpr.setExpression(propValueExpression);
//    castCefDataExpr.setType(
//        com.inspur.edp.cef.generator.overall.Utils.createTypeInfo(ICefData.class).getType(ast));
//
//    methodInvocation.arguments().add(castCefDataExpr);
//    StringLiteral propNameLiteral = ast.newStringLiteral();
//    propNameLiteral.setLiteralValue(element.getLabelID());
//    methodInvocation.arguments().add(propNameLiteral);
//    if(element instanceof IGspCommonElement) {
//      if (!element.getIsRefElement()
//          && udtDef instanceof SimpleDataTypeDef
//          && ((SimpleDataTypeDef) udtDef).getObjectType() == GspElementObjectType.Association
//          && element.containRefElementNotFromAssoUdt()) {
//        SerItemGenUtil
//            .addGetNestedSerializeContextArg_EnrichedAssoUdt(element, ast, methodInvocation);
//      } else {
//        SerItemGenUtil.addGetNestedSerializeContextArg(ast, methodInvocation);
//      }
//    }
//    result.add(ast.newExpressionStatement(methodInvocation));
//  }
//
//  private static void writeBasicElementGen(
//      AST ast, IGspCommonField element, ArrayList<Statement> result,
//      CefDataTypeImplGeneratorContext dataTypeGenContext, Expression propValueArgument) {
//    switch (element.getMDataType()) {
//      case String:
//      case Text:
//        writeStringElementGen(ast, element, result, propValueArgument);
//        break;
//      case Integer:
//        writeIntElementGen(ast, element, result, propValueArgument);
//        break;
//      case Decimal:
//        writeDecimalElementGen(ast, element, result, propValueArgument);
//        break;
//      case Date:
//        writeDateElementGen(ast, element, result, propValueArgument);
//        break;
//      case DateTime:
//        writeDateTimeElementGen(ast, element, result, dataTypeGenContext, propValueArgument);
//        break;
//      case Boolean:
//        writeBoolElementGen(ast, element, result, propValueArgument);
//        break;
//      case Binary:
//        writeBinaryElementGen(ast, element, result, propValueArgument);
//        break;
//      default:
//        throw new RuntimeException();
//    }
//  }
//
//  private static void writeBasicWriteString(
//      AST ast,
//      IGspCommonField element,
//      ArrayList<Statement> result,
//      String methodName,
//      Expression propValueArgument) {
//    MethodInvocation writeInvocation = ast.newMethodInvocation();
//    writeInvocation.setName(ast.newSimpleName(methodName));
//    writeInvocation.arguments().add(ast.newSimpleName(paramWriter));
//    writeInvocation.arguments().add(propValueArgument);
//    StringLiteral propNameLiteral = ast.newStringLiteral();
//    propNameLiteral.setLiteralValue(element.getLabelID());
//    writeInvocation.arguments().add(propNameLiteral);
//    writeInvocation.arguments().add(ast.newSimpleName(paramserializer));
//    result.add(ast.newExpressionStatement(writeInvocation));
//  }
//
//  private static void writeStringElementGen(
//      AST ast, IGspCommonField element, ArrayList<Statement> result, Expression propValueArgument) {
//    writeBasicWriteString(
//        ast, element, result, CMChangeJsonConvertorGenUtils.mName_WriteString, propValueArgument);
//  }
//
//  private static void writeIntElementGen(
//      AST ast, IGspCommonField element, ArrayList<Statement> result, Expression propValueArgument) {
//    writeBasicWriteString(
//        ast, element, result, CMChangeJsonConvertorGenUtils.mName_WriteInt, propValueArgument);
//  }
//
//  private static void writeDecimalElementGen(
//      AST ast, IGspCommonField element, ArrayList<Statement> result, Expression propValueArgument) {
//    writeBasicWriteString(
//        ast, element, result, CMChangeJsonConvertorGenUtils.mName_WriteDecimal, propValueArgument);
//  }
//
//  private static void writeDateElementGen(
//      AST ast, IGspCommonField element, ArrayList<Statement> result, Expression propValueArgument) {
//    writeBasicWriteString(
//        ast, element, result, CMChangeJsonConvertorGenUtils.mName_WriteDate, propValueArgument);
//  }
//
//  private static void writeDateTimeElementGen(
//      AST ast, IGspCommonField element, ArrayList<Statement> result,
//      CefDataTypeImplGeneratorContext dataTypeGenContext, Expression propValueArgument) {
//    if (SerItemGenUtil.getEnableStdDateTime(dataTypeGenContext)) {
//      writeBasicWriteString(
//          ast, element, result, CMChangeJsonConvertorGenUtils.mName_WriteStdDateTime,
//          propValueArgument);
//    } else {
//      writeBasicWriteString(
//          ast, element, result, CMChangeJsonConvertorGenUtils.mName_WriteDateTime,
//          propValueArgument);
//    }
//  }
//
//  private static void writeBoolElementGen(
//      AST ast, IGspCommonField element, ArrayList<Statement> result, Expression propValueArgument) {
//    writeBasicWriteString(
//        ast, element, result, CMChangeJsonConvertorGenUtils.mName_WriteBool, propValueArgument);
//  }
//
//  private static void writeBinaryElementGen(
//      AST ast, IGspCommonField element, ArrayList<Statement> result, Expression propValueArgument) {
//    writeBasicWriteString(
//        ast, element, result, CMChangeJsonConvertorGenUtils.mName_WriteBytes, propValueArgument);
//  }
//
//  // endregion WriteBasicElementGen
//
//  private static void writeAssElementGen(
//      AST ast,
//      IGspCommonField element,
//      ArrayList<Statement> result,
//      CefDataTypeImplGeneratorContext dataTypeGenContext,
//      Expression propValueArgument) {
//    // this.WriteXXXAssociation(writer, varTestItem.User, "User", serializer);
//    String mtdName = dataTypeGenContext.getAssociationWriteMetdNames().get(element.getLabelID());
//    // TODO:Java版临时注释 专用的关联序列化注释掉了先调用通用序列化
//    MethodInvocation writeAssInvocation = ast.newMethodInvocation();
//    writeAssInvocation.setName(
//        ast.newSimpleName(mtdName));
//    writeAssInvocation.arguments().add(ast.newSimpleName(paramWriter));
//    writeAssInvocation.arguments().add(propValueArgument);
//    // 20200703 wj-日期时间添加时区，为处理关联带出字段，修改使用生成的私有方法，替换原有writeAssociation()
////    StringLiteral propNameLiteral = ast.newStringLiteral();
////    propNameLiteral.setLiteralValue(element.getLabelID());
////    writeAssInvocation.arguments().add(propNameLiteral);
//    writeAssInvocation.arguments().add(ast.newSimpleName(paramserializer));
//    result.add(ast.newExpressionStatement(writeAssInvocation));
//  }
//
//  private static void writeEnumElementGen(
//      AST ast, IGspCommonField element, ArrayList<Statement> result, Expression propValueArgument) {
//    writeBasicWriteString(
//        ast, element, result, CMChangeJsonConvertorGenUtils.mName_WriteEnum, propValueArgument);
//  }
//
//  @Override
//  protected boolean getIsOverride() {
//    return true;
//  }
//
//  @Override
//  protected java.util.ArrayList<ModifierKeyword> getAccessModifiers() {
//    return new java.util.ArrayList<ModifierKeyword>(
//        java.util.Arrays.asList(new ModifierKeyword[]{ModifierKeyword.PUBLIC_KEYWORD}));
//  }
//
//  @Override
//  protected String getMethodName() {
//    return methodName;
//  }
//
//  // protected override List<ParameterInfo>  getParameterCollection()
//  // {
//  //    return new List<ParameterInfo>()
//  //    {
//  //        new ParameterInfo(typeof(JsonWriter),paramWriter),
//  //        new ParameterInfo(typeof(IValueObjData),paramData),
//  //        new ParameterInfo(typeof(JsonSerializer),paramserializer)
//  //    };
//  // }
//
//  @Override
//  protected TypeInfo getReturnType() {
//    return new TypeInfo("void");
//  }
//}
